package com.hyk.controller;


import com.hyk.dto.ApiResult;
import com.hyk.entity.Category;
import com.hyk.service.ICategoryService;
import com.hyk.utils.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Date;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author hyk
 * @since 2021-03-22
 */
@RestController
@RequestMapping("/category")
@Api(tags = "分类控制类")
@CrossOrigin
public class CategoryController {

    @Resource
    private ICategoryService categoryService;

    @ApiOperation("分类列表")
    @PostMapping("/list")
    public ApiResult list(){
        return R.ok(categoryService.list());
    }

    @ApiOperation("添加分类")
    @PostMapping("/add")
    public ApiResult add(@RequestBody Category category){

        category.setCreateTime(new Date());
        category.setUpdateTime(new Date());

        categoryService.save(category);
        return R.ok();
    }

}
